package com.yd.app.service.mobile.oldsRetriveService;

import com.yd.app.mapper.OldsRetrieveMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.Old;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.OldParam;
import com.yd.domain.sys.DicEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author zy
 * @create 2018-03-08 10:26
 * @desc 旧物管理
 **/
@Service
public class MOldsRetrieveService extends BaseService{
    @Autowired
    private OldsRetrieveMapper oldsRetrieveMapper;

    public PageModel getOldList(OldParam oldParam, int pageIndex, int pageSize){
        PageModel pm=new PageModel();
        List<Old> list=new ArrayList<>();
        list=oldsRetrieveMapper.searchOldList(oldParam,getStartRow(pageIndex,pageSize),pageSize);
        int count=0;
        if(pageIndex==1){
            //查询总条数
            count=oldsRetrieveMapper.searchOldCount(oldParam);
            pm.setCount(count);
        }
        pm.setList(list);
        return pm;
    }

    /**
     * 条件查询
     * @param oldParam
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public List<Old> getMyOldList(OldParam oldParam, int pageIndex, int pageSize){
        List<Old> list=new ArrayList<>();
        int startRow = getStartRow(pageIndex, pageSize);
        list=oldsRetrieveMapper.searchMyOld(oldParam,startRow,pageSize);
        return list;
    }

    public void addOld(Old o){
        o.setIfPic(true);
        oldsRetrieveMapper.addOld(o);
    }

    /**
     * @Author: zy
     * @Desc: 根据id查询旧物
     * @Date:  2018/4/13
     * @Param
     */
    public Old getOldByID(String id) {
        Old old=oldsRetrieveMapper.getOldByID(id);
        return old;
    }
    /**
     * @Author: zy
     * @Desc: 修改
     * @Date:  2018/4/16
     * @Param
     */
    public void updateOld(Old o) {
        if(o.getCheckUser()!=null&&!o.getCheckUser().equals("")){
            o.setCheckTime(new Date());
        }
        if(o.getDealStatus().equals(DicEnum.ORDER_STATUS.DEAL)){
            o.setDealTime(new Date());
        }
        oldsRetrieveMapper.updateOld(o);
    }
}
